All files / app/(public)/[username] page.tsx

42.59% Statements 259/608
56.25% Branches 27/48
100% Functions 3/3
42.59% Lines 259/608

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 8401x                                                                                                                                                                                           8x 8x   8x 8x 8x 8x 8x 8x   8x 2x 2x     6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x   6x 6x 6x 6x                         6x 6x 6x   6x 6x 6x 6x 6x 6x 6x 6x 6x     6x 6x 6x 6x 6x   8x                               8x                               6x                         6x 6x 6x     6x 6x 6x 6x 6x   6x   6x 6x 6x 6x 6x   6x 3x                                                                   3x 6x     6x 8x   3x 3x                                 3x   6x 6x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x   4x 4x 4x   4x 1x 1x 1x 1x   3x 4x   4x 4x 4x 4x 4x 4x 4x 4x 4x 3x   4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x   4x 4x 4x   4x 1x 1x   3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x   3x 3x   3x   3x   3x 3x 3x 3x 3x 3x 3x 3x 3x   3x 3x   3x 3x 3x 3x 3x 3x 3x 3x 4x   4x 4x     4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x     4x                                                   4x 1x 1x 1x 1x       4x               4x               4x               4x                                                                                                                                       4x                                                                                                                                     4x                                                                                                                                                                             4x 1x 1x 1x 1x       4x 1x 1x 1x 1x       4x                                                                                                                             4x 1x 1x 1x 1x       4x 1x 1x 1x 1x       4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x     4x 4x 4x 4x 4x   4x   4x 4x 4x 4x 4x   4x  
import { Metadata } from 'next';
import { notFound } from 'next/navigation';
import Link from 'next/link';
import Image from 'next/image';
import { createClient } from '@/lib/supabase/server';
import { ProfileHeader } from '@/components/profile/ProfileHeader';
import { Badge } from '@/components/ui/badge';
import { SampleGrid } from '@/components/samples/SampleGrid';
import { TestimonialList } from '@/components/testimonials/TestimonialList';
import { PackageList } from '@/components/packages/PackageList';
import { ContactButtons } from '@/components/profile/ContactButtons';
import { IdentityBadge } from '@/components/profile/IdentityBadge';
import { ProfileAnalytics } from '@/components/analytics/ProfileAnalytics';
import {
  VerificationBadges,
  HighestVerificationBadge,
} from '@/components/verification/VerificationBadges';
import { ExperienceTimeline } from '@/components/experience/ExperienceTimeline';
import { DeveloperSection } from '@/components/profile/DeveloperSection';
import { DesignerSection } from '@/components/profile/DesignerSection';
import { TutorSection } from '@/components/profile/TutorSection';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import {
  Scale,
  Stethoscope,
  Crown,
  Building2,
  CheckCircle2,
  Award,
  GraduationCap,
  LayoutTemplate,
  Download,
  Star,
} from 'lucide-react';
import type {
  UserBadge,
  WorkExperience,
  DeveloperProfile,
  CodeProject,
  DesignerProfile,
  GalleryItem,
  TutorProfile,
  Template,
} from '@/types/database';
 
// Vertical profile types (simplified for public display)
interface PublicDoctorProfile {
  primary_specialization: string | null;
  medical_degree: string | null;
  years_experience: number | null;
  registration_verified: boolean;
  accepting_patients: boolean;
  telemedicine_available: boolean;
  consultation_types: string[];
}
 
interface PublicLawyerProfile {
  primary_practice_area: string | null;
  law_degree: string | null;
  years_experience: number | null;
  bar_verified: boolean;
  bar_status: string | null;
  accepting_clients: boolean;
  consultation_available: boolean;
  practice_areas: string[];
}
 
interface PublicEliteProfile {
  public_name: string | null;
  title: string | null;
  industry: string | null;
  biography: string | null;
  identity_verified: boolean;
  notable_achievements: string[];
  wikipedia_url: string | null;
  linkedin_url: string | null;
}
 
interface VerticalMembership {
  id: string;
  status: string;
  approved_at: string | null;
  vertical: {
    code: string;
    name: string;
    icon: string | null;
    description: string | null;
  };
}
 
interface ProfilePageProps {
  params: Promise<{ username: string }>;
}
 
async function getProfile(username: string) {
  const supabase = await createClient();
 
  const { data: profile, error } = await supabase
    .from('profiles')
    .select('*')
    .eq('username', username.toLowerCase())
    .eq('is_published', true)
    .single();
 
  if (error || !profile) {
    return null;
  }
 
  // Fetch related data in parallel
  const [
    samplesResult,
    testimonialsResult,
    packagesResult,
    badgesResult,
    experiencesResult,
    verticalsResult,
    templatesResult,
  ] = await Promise.all([
    supabase
      .from('samples')
      .select('*')
      .eq('profile_id', profile.id)
      .order('display_order', { ascending: true }),
    supabase
      .from('testimonials')
      .select('*')
      .eq('profile_id', profile.id)
      .order('display_order', { ascending: true }),
    supabase
      .from('packages')
      .select('*')
      .eq('profile_id', profile.id)
      .eq('is_active', true)
      .order('display_order', { ascending: true }),
    supabase.rpc('get_user_badges', { user_uuid: profile.user_id }),
    supabase
      .from('work_experiences')
      .select('*')
      .eq('profile_id', profile.id)
      .eq('is_visible', true)
      .order('start_date', { ascending: false }),
    // Fetch active vertical memberships through identity
    supabase
      .from('identities')
      .select(
        `
        vertical_memberships!inner (
          id,
          status,
          approved_at,
          vertical:verticals (
            code,
            name,
            icon,
            description
          )
        )
      `
      )
      .eq('user_id', profile.user_id)
      .single(),
    // Fetch published templates
    supabase
      .from('templates')
      .select(
        'id, title, description, category, thumbnail_url, is_free, price_inr, downloads_count, rating_avg, rating_count, tags, tech_stack, created_at'
      )
      .eq('author_id', profile.id)
      .eq('is_published', true)
      .order('created_at', { ascending: false }),
  ]);
 
  // Fetch vertical-specific data based on profile type
  let developerProfile: DeveloperProfile | null = null;
  let codeProjects: CodeProject[] = [];
  let designerProfile: DesignerProfile | null = null;
  let galleryItems: GalleryItem[] = [];
  let tutorProfile: TutorProfile | null = null;
 
  if (profile.profile_type === 'developer') {
    const { data: devProfile } = await supabase
      .from('developer_profiles')
      .select('*')
      .eq('profile_id', profile.id)
      .single();
 
    if (devProfile) {
      developerProfile = devProfile;
      const { data: projects } = await supabase
        .from('code_projects')
        .select('*')
        .eq('developer_profile_id', devProfile.id)
        .order('display_order', { ascending: true });
      codeProjects = projects || [];
    }
  } else if (profile.profile_type === 'designer') {
    const { data: desProfile } = await supabase
      .from('designer_profiles')
      .select('*')
      .eq('profile_id', profile.id)
      .single();
 
    if (desProfile) {
      designerProfile = desProfile;
      const { data: items } = await supabase
        .from('gallery_items')
        .select('*')
        .eq('designer_profile_id', desProfile.id)
        .order('display_order', { ascending: true });
      galleryItems = items || [];
    }
  } else if (profile.profile_type === 'tutor') {
    const { data: tutProfile } = await supabase
      .from('tutor_profiles')
      .select('*')
      .eq('profile_id', profile.id)
      .single();
 
    if (tutProfile) {
      tutorProfile = tutProfile;
    }
  }
 
  // Fetch regulated vertical profiles (doctor, lawyer, elite) if user has active memberships
  let doctorProfile: PublicDoctorProfile | null = null;
  let lawyerProfile: PublicLawyerProfile | null = null;
  let eliteProfile: PublicEliteProfile | null = null;
 
  // Get identity to fetch vertical profiles
  const { data: identity } = await supabase
    .from('identities')
    .select('id')
    .eq('user_id', profile.user_id)
    .single();
 
  if (identity) {
    // Get active vertical memberships with their IDs
    const { data: activeMemberships } = await supabase
      .from('vertical_memberships')
      .select('id, vertical:verticals(code)')
      .eq('identity_id', identity.id)
      .eq('status', 'active');
 
    if (activeMemberships) {
      for (const membership of activeMemberships) {
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        const vertical = membership.vertical as any;
        const verticalCode = vertical?.code;
 
        if (verticalCode === 'doctor') {
          const { data: docProfile } = await supabase
            .from('doctor_profiles')
            .select(
              'primary_specialization, medical_degree, years_experience, registration_verified, accepting_patients, telemedicine_available, consultation_types'
            )
            .eq('membership_id', membership.id)
            .single();
          if (docProfile) doctorProfile = docProfile;
        } else if (verticalCode === 'lawyer') {
          const { data: lawProfile } = await supabase
            .from('lawyer_profiles')
            .select(
              'primary_practice_area, law_degree, years_experience, bar_verified, bar_status, accepting_clients, consultation_available, practice_areas'
            )
            .eq('membership_id', membership.id)
            .single();
          if (lawProfile) lawyerProfile = lawProfile;
        } else if (verticalCode === 'elite') {
          const { data: elProfile } = await supabase
            .from('elite_profiles')
            .select(
              'public_name, title, industry, biography, identity_verified, notable_achievements, wikipedia_url, linkedin_url'
            )
            .eq('membership_id', membership.id)
            .single();
          if (elProfile) eliteProfile = elProfile;
        }
      }
    }
  }
 
  // Extract and filter active vertical memberships
  const verticalMemberships: VerticalMembership[] = [];
  if (verticalsResult.data?.vertical_memberships) {
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    const memberships = verticalsResult.data.vertical_memberships as any[];
    for (const membership of memberships) {
      // Supabase returns vertical as an object (single relation) not array
      const vertical = membership.vertical;
      if (membership.status === 'active' && vertical) {
        verticalMemberships.push({
          id: membership.id,
          status: membership.status,
          approved_at: membership.approved_at,
          vertical: {
            code: vertical.code,
            name: vertical.name,
            icon: vertical.icon,
            description: vertical.description,
          },
        });
      }
    }
  }
 
  return {
    profile,
    samples: samplesResult.data || [],
    testimonials: testimonialsResult.data || [],
    packages: packagesResult.data || [],
    badges: (badgesResult.data || []) as UserBadge[],
    experiences: (experiencesResult.data || []) as WorkExperience[],
    templates: (templatesResult.data || []) as Template[],
    developerProfile,
    codeProjects,
    designerProfile,
    galleryItems,
    tutorProfile,
    verticalMemberships,
    doctorProfile,
    lawyerProfile,
    eliteProfile,
  };
}
 
export async function generateMetadata({ params }: ProfilePageProps): Promise<Metadata> {
  const { username } = await params;
  const data = await getProfile(username);
 
  if (!data) {
    return {
      title: 'Profile Not Found',
    };
  }
 
  const { profile } = data;
  const description = profile.bio || `${profile.display_name} - ${profile.role || 'Professional'}`;
 
  return {
    title: `${profile.display_name} - ${profile.role || 'Professional'}`,
    description: description.slice(0, 160),
    openGraph: {
      type: 'profile',
      title: profile.display_name,
      description: description.slice(0, 160),
      url: `/${profile.username}`,
      images: profile.avatar_url
        ? [{ url: profile.avatar_url, width: 400, height: 400 }]
        : undefined,
    },
    twitter: {
      card: 'summary',
      title: profile.display_name,
      description: description.slice(0, 160),
    },
    alternates: {
      canonical: `/${profile.username}`,
    },
  };
}
 
export default async function ProfilePage({ params }: ProfilePageProps) {
  const { username } = await params;
  const data = await getProfile(username);
 
  if (!data) {
    notFound();
  }
 
  const {
    profile,
    samples,
    testimonials,
    packages,
    badges,
    experiences,
    templates,
    developerProfile,
    codeProjects,
    designerProfile,
    galleryItems,
    tutorProfile,
    verticalMemberships,
    doctorProfile,
    lawyerProfile,
    eliteProfile,
  } = data;
 
  return (
    <>
      {/* Analytics Tracker (client component) */}
      <ProfileAnalytics profileId={profile.id} eventType="profile_view" />
 
      <div className="min-h-screen bg-background">
        {/* Header */}
        <header className="border-b bg-background/95 backdrop-blur">
          <div className="container flex h-14 items-center justify-between">
            <Link href="/" className="flex items-center gap-2">
              <Image src="/logo-3.png" width={28} height={28} alt="ProofID" />
              <span className="gradient-text text-lg font-bold">ProofID</span>
            </Link>
            <IdentityBadge code={profile.identity_code} />
          </div>
        </header>
 
        <main className="container py-8 md:py-12">
          <div className="mx-auto max-w-4xl">
            {/* Profile Header */}
            <div className="relative">
              <ProfileHeader
                displayName={profile.display_name}
                role={profile.role}
                bio={profile.bio}
                avatarUrl={profile.avatar_url}
                identityCode={profile.identity_code}
                verificationBadge={
                  badges.length > 0 ? <HighestVerificationBadge badges={badges} /> : null
                }
              />
            </div>
 
            {/* Contact Buttons */}
            <div className="mt-6">
              <ContactButtons
                whatsapp={profile.show_whatsapp ? profile.whatsapp : null}
                email={profile.show_email ? profile.email_public : null}
                linkedin={profile.linkedin_url}
                website={profile.website_url}
                twitter={profile.twitter_url}
                github={profile.github_url}
                profileId={profile.id}
              />
            </div>
 
            {/* Vertical Memberships */}
            {verticalMemberships.length > 0 && (
              <section className="mt-8">
                <h2 className="mb-4 text-lg font-semibold">Verified Credentials</h2>
                <div className="flex flex-wrap gap-2">
                  {verticalMemberships.map((membership) => (
                    <Badge
                      key={membership.id}
                      variant="outline"
                      className={
                        membership.vertical.code === 'elite'
                          ? 'border-amber-500 bg-amber-500/10 text-amber-700'
                          : membership.vertical.code === 'doctor'
                            ? 'border-green-500 bg-green-500/10 text-green-700'
                            : membership.vertical.code === 'lawyer'
                              ? 'border-blue-500 bg-blue-500/10 text-blue-700'
                              : 'border-purple-500 bg-purple-500/10 text-purple-700'
                      }
                    >
                      {membership.vertical.name}
                    </Badge>
                  ))}
                </div>
              </section>
            )}
 
            {/* Verification Badges */}
            {badges.length > 0 && (
              <section className="mt-8">
                <h2 className="mb-4 text-lg font-semibold">Verifications</h2>
                <VerificationBadges badges={badges} collapsible={true} maxVisible={3} />
              </section>
            )}
 
            {/* Developer Section */}
            {developerProfile && (
              <section className="mt-12">
                <h2 className="mb-6 text-2xl font-bold">Developer Profile</h2>
                <DeveloperSection developerProfile={developerProfile} projects={codeProjects} />
              </section>
            )}
 
            {/* Designer Section */}
            {designerProfile && (
              <section className="mt-12">
                <h2 className="mb-6 text-2xl font-bold">Design Portfolio</h2>
                <DesignerSection designerProfile={designerProfile} galleryItems={galleryItems} />
              </section>
            )}
 
            {/* Tutor Section */}
            {tutorProfile && (
              <section className="mt-12">
                <h2 className="mb-6 text-2xl font-bold">Tutoring Services</h2>
                <TutorSection tutorProfile={tutorProfile} />
              </section>
            )}
 
            {/* Doctor Profile Section */}
            {doctorProfile && (
              <section className="mt-12">
                <Card className="border-green-500/30 bg-green-500/5">
                  <CardHeader>
                    <CardTitle className="flex items-center gap-2">
                      <Stethoscope className="h-5 w-5 text-green-600" />
                      Medical Professional
                    </CardTitle>
                    <CardDescription>Verified healthcare credentials</CardDescription>
                  </CardHeader>
                  <CardContent>
                    <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
                      {doctorProfile.primary_specialization && (
                        <div>
                          <p className="text-sm text-muted-foreground">Specialization</p>
                          <p className="font-medium capitalize">
                            {doctorProfile.primary_specialization.replace(/_/g, ' ')}
                          </p>
                        </div>
                      )}
                      {doctorProfile.medical_degree && (
                        <div>
                          <p className="text-sm text-muted-foreground">Qualification</p>
                          <p className="font-medium">{doctorProfile.medical_degree}</p>
                        </div>
                      )}
                      {doctorProfile.years_experience && (
                        <div>
                          <p className="text-sm text-muted-foreground">Experience</p>
                          <p className="font-medium">{doctorProfile.years_experience} years</p>
                        </div>
                      )}
                      <div>
                        <p className="text-sm text-muted-foreground">Registration</p>
                        <Badge
                          variant={doctorProfile.registration_verified ? 'default' : 'secondary'}
                        >
                          {doctorProfile.registration_verified ? (
                            <>
                              <CheckCircle2 className="mr-1 h-3 w-3" /> Verified
                            </>
                          ) : (
                            'Pending'
                          )}
                        </Badge>
                      </div>
                    </div>
                    <div className="mt-4 flex flex-wrap gap-2">
                      {doctorProfile.accepting_patients && (
                        <Badge variant="outline" className="border-green-500 text-green-700">
                          Accepting Patients
                        </Badge>
                      )}
                      {doctorProfile.telemedicine_available && (
                        <Badge variant="outline">Telemedicine Available</Badge>
                      )}
                      {doctorProfile.consultation_types?.map((type) => (
                        <Badge key={type} variant="secondary" className="capitalize">
                          {type.replace(/_/g, ' ')}
                        </Badge>
                      ))}
                    </div>
                  </CardContent>
                </Card>
              </section>
            )}
 
            {/* Lawyer Profile Section */}
            {lawyerProfile && (
              <section className="mt-12">
                <Card className="border-blue-500/30 bg-blue-500/5">
                  <CardHeader>
                    <CardTitle className="flex items-center gap-2">
                      <Scale className="h-5 w-5 text-blue-600" />
                      Legal Professional
                    </CardTitle>
                    <CardDescription>Verified legal credentials</CardDescription>
                  </CardHeader>
                  <CardContent>
                    <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
                      {lawyerProfile.primary_practice_area && (
                        <div>
                          <p className="text-sm text-muted-foreground">Practice Area</p>
                          <p className="font-medium capitalize">
                            {lawyerProfile.primary_practice_area.replace(/_/g, ' ')}
                          </p>
                        </div>
                      )}
                      {lawyerProfile.law_degree && (
                        <div>
                          <p className="text-sm text-muted-foreground">Qualification</p>
                          <p className="font-medium">{lawyerProfile.law_degree}</p>
                        </div>
                      )}
                      {lawyerProfile.years_experience && (
                        <div>
                          <p className="text-sm text-muted-foreground">Experience</p>
                          <p className="font-medium">{lawyerProfile.years_experience} years</p>
                        </div>
                      )}
                      <div>
                        <p className="text-sm text-muted-foreground">Bar Status</p>
                        <Badge variant={lawyerProfile.bar_verified ? 'default' : 'secondary'}>
                          {lawyerProfile.bar_verified ? (
                            <>
                              <CheckCircle2 className="mr-1 h-3 w-3" />{' '}
                              {lawyerProfile.bar_status || 'Verified'}
                            </>
                          ) : (
                            'Pending'
                          )}
                        </Badge>
                      </div>
                    </div>
                    <div className="mt-4 flex flex-wrap gap-2">
                      {lawyerProfile.accepting_clients && (
                        <Badge variant="outline" className="border-blue-500 text-blue-700">
                          Accepting Clients
                        </Badge>
                      )}
                      {lawyerProfile.consultation_available && (
                        <Badge variant="outline">Consultations Available</Badge>
                      )}
                      {lawyerProfile.practice_areas?.map((area) => (
                        <Badge key={area} variant="secondary" className="capitalize">
                          {area.replace(/_/g, ' ')}
                        </Badge>
                      ))}
                    </div>
                  </CardContent>
                </Card>
              </section>
            )}
 
            {/* Elite Profile Section */}
            {eliteProfile && (
              <section className="mt-12">
                <Card className="border-amber-500/30 bg-gradient-to-br from-amber-500/5 to-yellow-500/5">
                  <CardHeader>
                    <CardTitle className="flex items-center gap-2">
                      <Crown className="h-5 w-5 text-amber-600" />
                      Elite Professional
                      {eliteProfile.identity_verified && (
                        <Badge className="ml-2 bg-amber-500/20 text-amber-700">
                          <CheckCircle2 className="mr-1 h-3 w-3" /> Verified
                        </Badge>
                      )}
                    </CardTitle>
                    <CardDescription>Distinguished industry leader</CardDescription>
                  </CardHeader>
                  <CardContent>
                    <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
                      {eliteProfile.title && (
                        <div>
                          <p className="text-sm text-muted-foreground">Title</p>
                          <p className="font-medium">{eliteProfile.title}</p>
                        </div>
                      )}
                      {eliteProfile.industry && (
                        <div>
                          <p className="text-sm text-muted-foreground">Industry</p>
                          <p className="font-medium capitalize">
                            {eliteProfile.industry.replace(/_/g, ' ')}
                          </p>
                        </div>
                      )}
                      {(eliteProfile.wikipedia_url || eliteProfile.linkedin_url) && (
                        <div>
                          <p className="text-sm text-muted-foreground">Profiles</p>
                          <div className="flex gap-2">
                            {eliteProfile.wikipedia_url && (
                              <a
                                href={eliteProfile.wikipedia_url}
                                target="_blank"
                                rel="noopener noreferrer"
                                className="text-sm text-primary hover:underline"
                              >
                                Wikipedia
                              </a>
                            )}
                            {eliteProfile.linkedin_url && (
                              <a
                                href={eliteProfile.linkedin_url}
                                target="_blank"
                                rel="noopener noreferrer"
                                className="text-sm text-primary hover:underline"
                              >
                                LinkedIn
                              </a>
                            )}
                          </div>
                        </div>
                      )}
                    </div>
                    {eliteProfile.biography && (
                      <div className="mt-4">
                        <p className="text-sm text-muted-foreground">Biography</p>
                        <p className="mt-1 line-clamp-3 text-sm">{eliteProfile.biography}</p>
                      </div>
                    )}
                    {eliteProfile.notable_achievements &&
                      eliteProfile.notable_achievements.length > 0 && (
                        <div className="mt-4">
                          <p className="mb-2 text-sm text-muted-foreground">Notable Achievements</p>
                          <div className="flex flex-wrap gap-2">
                            {eliteProfile.notable_achievements
                              .slice(0, 5)
                              .map((achievement, idx) => (
                                <Badge key={idx} variant="outline" className="border-amber-500/50">
                                  <Award className="mr-1 h-3 w-3 text-amber-600" />
                                  {achievement}
                                </Badge>
                              ))}
                          </div>
                        </div>
                      )}
                  </CardContent>
                </Card>
              </section>
            )}
 
            {/* Work Experience */}
            {experiences.length > 0 && (
              <section className="mt-12">
                <h2 className="mb-6 text-2xl font-bold">Experience</h2>
                <ExperienceTimeline experiences={experiences} />
              </section>
            )}
 
            {/* Work Samples */}
            {samples.length > 0 && (
              <section className="mt-12">
                <h2 className="mb-6 text-2xl font-bold">Work Samples</h2>
                <SampleGrid samples={samples} profileId={profile.id} />
              </section>
            )}
 
            {/* Published Templates */}
            {templates.length > 0 && (
              <section className="mt-12">
                <h2 className="mb-6 text-2xl font-bold">Templates</h2>
                <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
                  {templates.map((template) => (
                    <Link key={template.id} href={`/templates/${template.id}`} className="group">
                      <Card className="h-full overflow-hidden transition-all hover:shadow-lg">
                        <div className="relative aspect-[16/10] overflow-hidden bg-muted">
                          {template.thumbnail_url ? (
                            <Image
                              src={template.thumbnail_url}
                              alt={template.title}
                              fill
                              className="object-cover transition-transform group-hover:scale-105"
                            />
                          ) : (
                            <div className="flex h-full items-center justify-center">
                              <LayoutTemplate className="h-12 w-12 text-muted-foreground/50" />
                            </div>
                          )}
                          <div className="absolute right-2 top-2">
                            {template.is_free ? (
                              <Badge className="bg-green-500 text-white">Free</Badge>
                            ) : (
                              <Badge className="bg-primary text-primary-foreground">
                                &#8377;{template.price_inr}
                              </Badge>
                            )}
                          </div>
                        </div>
                        <CardContent className="p-4">
                          <h3 className="mb-1 truncate font-semibold group-hover:text-primary">
                            {template.title}
                          </h3>
                          {template.description && (
                            <p className="mb-3 line-clamp-2 text-sm text-muted-foreground">
                              {template.description}
                            </p>
                          )}
                          <div className="flex items-center gap-3 text-xs text-muted-foreground">
                            <span className="flex items-center gap-1">
                              <Download className="h-3 w-3" />
                              {template.downloads_count}
                            </span>
                            {template.rating_count > 0 && (
                              <span className="flex items-center gap-1">
                                <Star className="h-3 w-3 fill-yellow-400 text-yellow-400" />
                                {Number(template.rating_avg).toFixed(1)}
                              </span>
                            )}
                            <Badge variant="outline" className="text-[10px] capitalize">
                              {template.category.replace(/_/g, ' ')}
                            </Badge>
                          </div>
                        </CardContent>
                      </Card>
                    </Link>
                  ))}
                </div>
              </section>
            )}
 
            {/* Packages/Pricing */}
            {packages.length > 0 && (
              <section className="mt-12">
                <h2 className="mb-6 text-2xl font-bold">Services & Pricing</h2>
                <PackageList packages={packages} profileId={profile.id} />
              </section>
            )}
 
            {/* Testimonials */}
            {testimonials.length > 0 && (
              <section className="mt-12">
                <h2 className="mb-6 text-2xl font-bold">Testimonials</h2>
                <TestimonialList testimonials={testimonials} profileId={profile.id} />
              </section>
            )}
 
            {/* Verification CTA */}
            <section className="mt-16 rounded-lg border bg-muted/30 p-6 text-center">
              <p className="mb-2 text-sm text-muted-foreground">Verify this identity</p>
              <code className="identity-code text-lg text-primary">{profile.identity_code}</code>
              <p className="mt-2 text-sm text-muted-foreground">
                Visit{' '}
                <Link href={`/verify/${profile.identity_code}`} className="text-primary underline">
                  proofid.in/verify/{profile.identity_code}
                </Link>
              </p>
            </section>
          </div>
        </main>
 
        {/* Footer */}
        <footer className="border-t py-8">
          <div className="container text-center text-sm text-muted-foreground">
            <p>
              Powered by{' '}
              <Link href="/" className="text-primary hover:underline">
                ProofID
              </Link>{' '}
              - Proof-of-work identity for independent workers
            </p>
          </div>
        </footer>
      </div>
    </>
  );
}